define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'hdright/index' + location.search,
                    add_url: 'hdright/add',
                    edit_url: 'hdright/edit',
                    del_url: 'hdright/del',
                    multi_url: 'hdright/multi',
                    import_url: 'hdright/import',
                    table: 'hdright',
                }
            });

            code_arr = '';
            code_sum = 1;


            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showColumns: false,
                commonSearch: false,
                pageSize:1000,
                sortOrder: 'asc',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'target_code', title: __('Target_code'), operate: false, table: table, class: 'autocontent', formatter: function(value,row,index){

                            code_arr += value+',';
                            code_sum++;
                        return '<button value="'+value+'" class="btn btn-success copy-link" title="Copy" style="font-size: 15px;">'+value+'</button>';
    
                        }},
                        {field: 'target_name', title: __('Target_name'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'self_code', title: __('Self_code'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'self_name', title: __('Self_name'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });






                $(document).on("click", ".copy-link", function(){
                var url = $(this).val();
                $(this).removeClass("btn-success").addClass("btn-warning");
                /**点击按钮,复制链接地址...*/
                var oInput = document.createElement('input');
                oInput.value = url;
                document.body.appendChild(oInput);
                oInput.select();//选择对象
                document.execCommand("Copy"); //
                oInput.className = 'oInput'
                oInput.style.display='none';
                layer.msg('复制成功')
               
                })


                $(document).on("click", ".save_to_arr", function(){
                    code_arr = code_arr.slice(0, -1);
                    var str = code_arr;

                    $(this).removeClass("btn-success").addClass("btn-warning");
                    /**点击按钮,复制链接地址...*/
                    var oInput = document.createElement('input');
                    oInput.value = str;
                    document.body.appendChild(oInput);
                    oInput.select();//选择对象
                    document.execCommand("Copy"); //
                    oInput.className = 'oInput'
                    oInput.style.display='none';
                    layer.msg('复制成功')
                
                    // console.log(str);
                    // alert(1);

                 })

                function removeLastCharacter(str) {
                    return str.slice(0, -1);
                }


            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            // Controller.api.bindevent();


            
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
